// pages/goods/index.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    goodsList: [],
    tablist: [{
        id: 0,
        title: "全部"
      },

    ],
    tabIndex: 0, //tab栏默认选中第一个
    scrollLeft: 0,
    class_id: 0,
    store: [],
    index: 0,
    store_id: "",
    isGoodsList: true,
    isPageOptLinkOut: false
  },
  onShow() {
    const that = this
    that.getList()
  },
  getList() {
    const that = this
    app.http.post(app.api.goods, {
      class_id: that.data.class_id
    }, (res) => {
      console.log(res.data.class)
      if (res.data.goods == "") {
        that.setData({
          tablist: res.data.class,
          goodsList: res.data.goods,
          isGoodsList: true
        })
      } else {
        that.setData({
          tablist: res.data.class,
          goodsList: res.data.goods,
          isGoodsList: false
        })
      }
    })
  },


  scroll(e) {
    // console.log(2,e.currentTarget.offsetLeft,this.data.scrollLeft)
  },
  // 切换tab栏
  chooseTab(e) {
    console.log(this.data.class_id, e.currentTarget.dataset.id);
    app.globalData.isUnload = true
    let id = e.currentTarget.dataset.id
    if (e.currentTarget.offsetLeft > 150) {
      this.setData({
        class_id: this.data.tablist[id],
        tabIndex: id,
        scrollLeft: e.currentTarget.offsetLeft - 150
      });
    } else {
      this.setData({
        class_id: this.data.tablist[id],
        tabIndex: id,
        scrollLeft: 0
      });
    }
    this.getList()
  },
  goodsEx(e) {
    wx.navigateTo({
      url: "/pages/goods/detail/index?id=" + e.currentTarget.dataset.id,
    });
  },
  onShareAppMessage() {

  },
  onUnload() {
    const that = this
    console.log(`onUnload - MakeDelete1`, this.data.isPageOptLinkOut, app.globalData.isUnload)
  },
  onShareTimeline() {}
});